class AudioManager {
    constructor() {
        this.sounds = {
            background: new Audio('/audio/background.mp3'),
            deal: new Audio('/audio/deal.mp3'),
            play: new Audio('/audio/play.mp3'),
            win: new Audio('/audio/win.mp3'),
            lose: new Audio('/audio/lose.mp3')
        };
        
        // 设置背景音乐循环播放
        this.sounds.background.loop = true;
    }
    
    play(soundName) {
        const sound = this.sounds[soundName];
        if (sound) {
            sound.currentTime = 0;
            sound.play().catch(e => console.log('播放音效失败:', e));
        }
    }
    
    stop(soundName) {
        const sound = this.sounds[soundName];
        if (sound) {
            sound.pause();
            sound.currentTime = 0;
        }
    }
    
    toggleBackgroundMusic() {
        const bgm = this.sounds.background;
        if (bgm.paused) {
            bgm.play().catch(e => console.log('播放背景音乐失败:', e));
        } else {
            bgm.pause();
        }
    }
}

const audioManager = new AudioManager(); 